import { purtcList } from '@/api/url/salesOrderManagement';
import router from '@/router';
import { isNullPm } from '@/utils/baseMethods';
import { nextTick, onMounted, onUnmounted, reactive } from 'vue';
import XEClipboard from 'xe-clipboard';
import { VXETable } from 'vxe-table';
import { dayjs } from '@arco-design/web-vue/es/_utils/date';
import { factoryList, resourceList, resourceTypeList } from '@api/url/productionManagement';

export default function importConfig() {
  const base = reactive<any>({
    tableList: [],
    visible: false,
    desData: null,
  });

  //获取表格数据
  const getTable = () => {
    resourceTypeList().then((res: any) => {
      if (res.code === '200') {
        base.tableList = res.data;
      }
    });
  };

  //页码或页数改变时发生的事件
  const handlePageChange = () => {
    getTable();
  };

  /**
   * @exports menuConfig 表单配置器
   */
  const menuConfig = reactive<any>({
    className: 'my-menus',
    body: {
      options: [
        [{ code: 'copy', name: '复制', prefixIcon: 'vxe-icon-copy', className: 'my-copy-item' }],
        [{ code: 'viewDetails', name: '查看详情', prefixIcon: 'vxe-icon-success-circle-fill', className: 'my-copy-item' }],
      ],
    },
  });
  /**
   * @exports contextMenuBodyClickEvent 表单操作格式
   * @param param0
   */
  const contextMenuBodyClickEvent = ({ menu, row, column }) => {
    switch (menu.code) {
      case 'viewDetails':
        viewDetails(row);
        break;
      case 'copy':
        // 示例
        if (row && column) {
          console.log(row, column);
          if (XEClipboard.copy(row[column.field])) {
            VXETable.modal.message({ content: '已复制到剪贴板！', status: 'success' });
          }
        }
        break;
      default:
        console.log(`点击了 ${menu.name} 选项`, row, column, row[column.field]);
    }
  };

  /**
   * @exports viewDetails 查看采购单详情
   */
  const viewDetails = (param) => {
    router.push({ path: '/purchaseOrderDetails', query: { type: param.type, id: param.id } });
  };

  onMounted(() => {
    getTable();
  });

  return {
    base,
    menuConfig,
    handlePageChange,
    contextMenuBodyClickEvent,
    viewDetails,
    getTable,
  };
}
